﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AdornerPopup.Sample
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {

        private List<string> _dataSource = new List<string>();
        public ObservableCollection<string> SearchResults { get; set; } = new ObservableCollection<string>();

        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;

            InitDataSource();
        }

        private void InitDataSource()
        {
            Random random = new Random((int)DateTime.Now.Ticks);
            for (int i = 0; i < 1000; i++)
            {
                int num = (int)(random.NextDouble() * 1000);
                _dataSource.Add(num.ToString());
            }
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            SearchResults.Clear();
            var result = _dataSource.Where(p => p.IndexOf(tbInput.Text, StringComparison.InvariantCultureIgnoreCase) != -1);
            foreach (var item in result)
            {
                SearchResults.Add(item);
            }
            adornerPopup.IsOpen = !adornerPopup.IsOpen;
        }
    }
}
